package com.realgodo.site.web.admin.user;

import java.util.Date;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import com.realgodo.site.entity.security.User;
import com.realgodo.site.service.UserManager;
import com.realgodo.site.web.admin.AdminDefaultController;

@Scope("prototype")
@Results( { @Result(name = "toindex", type = "redirect", location = "${base}/admin/user/") })
public class OfficialController extends AdminDefaultController {

	private static final long serialVersionUID = -5209270070845804609L;

	private User user;

	@Autowired
	private UserManager userManager;

	public String index() {
		return SUCCESS;
	}

	/** 注册用户 */
	public String regist() {

		String uncodePassword = user.getPassword();
		user.setEnable(User.ENABLED);
		user.setActiveCode(String.valueOf(new Date().getTime()));
		user = this.userManager.createUser(user);
		user.setPassword(uncodePassword);
		user = userManager.get(user.getId());

		return "toindex";
	}

	/************ getter and setter *******************/

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

}
